<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Arrays</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="../js/underscore.js"></script>
    <script>
        var array = [1, 3, 4, 2, 5, 9, 8, 6, 7];
        //取第一个值
        console.log('first in ' + JSON.stringify(array) + ' is ' + _.first(array));
        //取最后一个值
        console.log('last in ' + JSON.stringify(array) + ' is ' + _.last(array));
        array = [1, [2, [3, [4, [5, [6, 7]]]]]];
        //将多维数组处理为一维数组
        console.log('flatten ' + JSON.stringify(array) + ' is ' + JSON.stringify(_.flatten(array)));
        var names = ['Adam', 'Lisa', 'Bart'];
        var scores = [85, 92, 59];
        var zip = _.zip(names, scores);
        //将多个一维数组合并为多维数组
        console.log('zip ' + JSON.stringify(names) + ' and ' + JSON.stringify(scores) + ' is ' + JSON.stringify(zip));
        //将多维数组拆分为多个一维数组
        console.log('unzip ' + JSON.stringify(zip) + ' is ' + JSON.stringify(_.unzip(zip)));
        var object = _.object(names, scores);
        //将多个数组合并为对象
        console.log('object ' + JSON.stringify(names) + ' and ' + JSON.stringify(scores) + ' is ' + JSON.stringify(object));
        //生成序列，从0开始小于30，步长为5
        console.log('_.range(0, 30, 5) ' + ' is ' + JSON.stringify(_.range(0, 30, 5)));
        var arr = ['Apple', 'orange', 'banana', 'ORANGE', 'apple', 'PEAR'];
        //不区分大小写去重
        console.log('_.uniq(' + JSON.stringify(arr) + ') is ' + JSON.stringify(_.uniq(arr, false, function (value) {
            return value.toLowerCase();
        })));
    </script>
</head>

<body>

</body>

</html>